<?php
function V_DownloadDriverList(&$arrayData){
	$ulr = "?".MODUL."=downloaddriver&".ACTION."=";
	
?>
<?= CM_showError() ?>
<?
	$tieu_de =$arrayData['tieu_de'];
?>
	<font size="4" color="#FF0000">Download driver: <a href="<?=$ulr?>Add" class="thanh_link1"><strong><font size="2"> Thêm mới</font></strong></a><font size="2">&nbsp;</font></font> <br>
    <hr width="30%" size="1" align="left">
<?
    	//phan trang
    	$totalRows = 0;
		$paging="";
		$totalRows=count($arrayData);
		$maxRows = MAXROW;
		$maxPages =MAXPAGES;
		if($totalRows%$maxRows==0)
			$totalPages = (int)($totalRows/$maxRows);
		else
			$totalPages = (int)($totalRows/$maxRows+1);
		$curPage =CM_getParameter("curPg");
		if($curPage=="")
			$curPage =1;
		else
			$curRow = ($curPage-1)*$maxRows+1;
		$paging ="Trang thứ :&nbsp;<font color=red>".$curPage."</font>&nbsp;&nbsp;&nbsp;"."Tổng số trang :&nbsp;<FONT color=red>".$totalPages."</FONT><br> ";
		if($totalRows>$maxRows)
		{
			$start=1;
			$end=1;
			$paging1 ="";
			for($i=1;$i<=$totalPages;$i++)
			{
				if(($i>((int)(($curPage-1)/$maxPages))* $maxPages) && ($i<=((int)(($curPage-1)/$maxPages+1))* $maxPages))
				{
					if($start==1) $start=$i;
						if($i==$curPage)
							$paging1 .=  $i."&nbsp;&nbsp;";
						else
							$paging1 .= "<a href='javascript:GotoPage(".$i.")'>".$i."</a>&nbsp;&nbsp;";
					$end=$i;
				}
			}
			$paging.= "Chọn trang :&nbsp;&nbsp;" ;
			if($curPage>$maxPages)
				$paging .="<a href='javascript:GotoPage(".($start-1).")'>Trở về</a>&nbsp;&nbsp;";
			$paging.=$paging1;
			if(((($curPage-1)/$maxPages+1)*$maxPages) < $totalPages)
				$paging .= "<a href='javascript:GotoPage(".($end+1).")'>Tiếp</a>&nbsp;&nbsp;";
		}
?>
<script>
function GotoPage(iPage){
	document.frm.action =document.frm.action  + "&curPg="+iPage;
	document.frm.submit()  ;
}
</script>
<table width="97%" align="center">
  <tr><td>
<form name="frm" action="<?=$ulr?>list"  method="post" >
<DIV style="BORDER-RIGHT: #999999 1px solid; VERTICAL-ALIGN: top; OVERFLOW: auto; BORDER-LEFT: #999999 1px solid; WIDTH: 810px; BORDER-BOTTOM: #999999 1px solid; HEIGHT: 400px" align="center">
<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<TBODY>
		  <TR align="center" bgcolor="#FFE59F">
			<TD width="28" height="21" align="center" valign="middle" id=th1><font size="2"><strong>STT</strong></font></TD>
			<TD width="23" align="center" valign="middle"><font size="2"><strong>Sửa</strong></font></TD>
			<TD width="23" align="center" valign="middle" id=th3><font size="2"><strong>Xóa</strong></font></TD>
			<TD width="249" align="left" valign="middle" id=th4><font size="2"><strong>Tiêu đề </strong></font></TD>
			<TD width="269" align="left" valign="middle" id=th5><font size="2"><strong>Tên danh mục</strong></font></TD>
			<TD width="166" align="right" valign="middle" id=th7><font size="2"><strong>Ngày đăng</strong></font></TD>
		 </TR>
	<?
	//=======================================================================================
	if(count($arrayData)>0)
	{
		$i=0;
		$low=$curRow;
		$curRow=1;
		$stt=0;
		foreach($arrayData as $row)
		{
			$stt+=1;
			if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
			{
				
				$curRow++;
				if($curRow>$low){
					$i+1;
	?>
	  <TR>
		
		<TD height="22" align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F"><strong><font size="2"><? echo $stt ?></font></strong></TD>
		<TD align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F">
			<a  href="<?=$ulr."Edit"?>&id=<? echo $row['id']; ?>&id_danh_muc=<?=$row['id_danh_muc']?>&curPg=<?=CM_getParameter("curPg");?>" onclick="return edit('<?=$row['id']?>','<?=$row['id_danh_muc']?>');">
				<img   title="Change" height=16 alt="Change" hspace=2   src="../images/Edit.gif" width=16 border=0>
			</a>
		</TD>
		<TD align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F">
			<A  onclick="return del('<?=$row['id']?>');" 
				href="<?=$ulr."Delete"?>&id=<? echo $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>">
					<IMG title="Drop" height=16 alt="Drop" hspace=2 src="../images/Delete.gif" width=16 border=0>
			</A>
		</TD>
		<TD align="center" valign="middle" class=bk12-140  > 
			<div align="left">
			    <font size="2"><? echo $row['ten_danh_muc']; ?>
          </font></div></TD>
		<TD align="left" valign="middle" class=bk12-140> 
		  <div align="left"><font size="2">
				<?
					global $db;
					include_once(DIR_MODEL."md_cat_san_pham.class.php");
					$objcatSanpham = new MD_CatSanpham($db);
					$arrayDataCat =  array();  
					$arrayDataCat = $objcatSanpham->getByWhere("*","id=".$row['id_danh_muc']."","");
					echo $arrayDataCat[0]['ten_loai_sp'];
				?>
				
          </font></div></TD>
		
		<TD align="left" valign="middle" class=bk12-140>
			<div align="right"><font size="2">
			    <? echo str_replace("-","/",$row['ngay_dang']); ?>&nbsp;
          </font></div></TD>
	  </TR>
	  
	 <?
				} // end if($curRow>$low)
			}// end if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
		} // end foreach($arrayData as $row)
	} // end if($arrayData>0)
	else
	{
?>
	  <tr valign="top">
			<td colspan=9 valign=center align="center"><b><font face="Arial" color="#FF0000">Không có bản ghi nào </font></b></td>
      </tr>
      <?php
		}
	  ?>

</TBODY>
</TABLE>
</div>

<table border="0" width="99%">
				<!--DWLayoutTable-->
				
				<tr>
				    <td width="363" rowspan="2" align=left>
					  <div align="left"><font face="Arial" color="#0066cc">Tổng số bản ghi <b><font color="#ff0000">
						<? echo($totalRows);?></font></b></font></div>
						 <hr width="40%" size="1" align="left">		  
				    </td>
				    <td width="565" height="23" align=right valign="top"><?=$paging?></td>
				</tr>
				<tr>
				   <td height="15" align="right" valign="top">
				 	<A class="thanh_link1" href="<?=$ulr1?>">[<strong>Trở về </strong>]</a>&nbsp;&nbsp;&nbsp; 
				   </td>			 
				</tr>
</table>
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>"> 
<input type=hidden name="section_idS" value="<?=CM_getParameter("section_idS")?>"> 
<input type=hidden name="hien_thiS" value="<?=CM_getParameter("hien_thiS")?>"> 
<input type=hidden name="curPg" >
</form>
</td></tr></table>
<script language=javascript>
function upadate(){
	var frm  = document.forms["frm"];
	frm.action  = '<?=$ulr?>Update&curPg=<?=CM_getParameter("curPg")?>';
	frm.submit();
	return false;
}
function edit(id,id_danh_muc){
	var frm  = document.forms["frm"];
	frm.action  = '<?=$ulr?>Edit&curPg=<?=CM_getParameter("curPg")?>&id='+id+'&id_danh_muc='+id_danh_muc;
	frm.submit();
	return false;
}
function View(id){
	var frm  = document.forms["frm"];
	frm.action  = '<?=$ulr?>View&curPg=<?=CM_getParameter("curPg")?>&id='+id;
	frm.submit();
	return false;
}
function del(id){
	if( ! confirmDelete() ) return;
	var frm  = document.forms["frm"];
	frm.action  = '<?=$ulr?>Delete&curPg=<?=CM_getParameter("curPg")?>&id='+id;
	frm.submit();
	return false;
}

//  -----------------End ---------------------------->
</script>
<?php
}
?>